//创建返回对象
var resultweb = {
    TypeId: 0,
    Type: "",
    Message: ""
}


//创建div元素
let toolDiv = document.createElement("div");
//toolDiv.id = "yk_toolDiv";
//toolDiv.style.position = "fixed";
//toolDiv.style.top = "0";
//toolDiv.style.left = "50%";
//toolDiv.style.zIndex = "9999";


//插入html工具台
toolDiv.innerHTML = "<div id=\"yk_mySidebar\" class=\"yk_sidebar\"><a href=\"javascript:void(0)\" class=\"yk_closebtn\">×</a><button id=\"getDmId\" class=\"yk_button\">获取弹幕数据</button><button id=\"yk_setlog\" class=\"yk_button\">控制台输出</button></div><div class=\"yk_openbtndiv\"><a href=\"javascript:void(0)\" class=\"yk_openbtn\">⇅</a></div>";
document.body.appendChild(toolDiv);

document.getElementsByClassName("yk_sidebar")[0].style.cssText = "height: 200px;width:50%;position: fixed;z-index: 9999;top: 0;left: 25%;background-color: rgb(125 68 190 / 0.80);overflow-x: hidden;overflow-y:hidden;transition: 0.5s;er";
document.getElementsByClassName("yk_sidebar")[0].getElementsByTagName("a")[0].style.cssText = "padding: 8px 8px 8px 32px;text-decoration: none;font-size: 25px;color: #818181;display: block;transition: 0.3s;";
document.getElementsByClassName("yk_closebtn")[0].style.cssText = " position: absolute;top: 0;right: 25px;font-size: 36px;margin-left: 50px;";
document.getElementsByClassName("yk_openbtndiv")[0].style.cssText = " width: 400px;position: fixed;z-index: 1;top: 0;left: 40%;background-color: rgb(125 68 190 / 0.80);margin-top: 100px;display:none;transition: 0.3s;";
document.getElementsByClassName("yk_openbtn")[0].style.cssText = " background-color: blueviolet;padding: 8px 20px;text - decoration: none;color: #818181;display: block;transition: 0.3s;position: absolute;top: 0;right: 25px;font - size: 36px;margin - left: 50px; ";
for (var i = 0; i < document.getElementsByClassName("yk_button").length; i++) {

    document.getElementsByClassName("yk_button")[i].style.cssText = "background-color: #f1f1f1;border: 2px solid #dcdfe6;color: #333333;padding: 8px 16px;text-align: center;text-decoration: none;display: inline-block;font-size: 16px;margin: 4px 2px;cursor: pointer;border-radius: 12px; box-shadow: 5px 10px rgba(0,0,0,0.19);"
}


//////////////////////////
//样式方法
function yk_openNav() {
    document.getElementById("yk_mySidebar").style.height = "200px";
    document.getElementsByClassName("yk_openbtndiv")[0].style.display = "none";
    document.getElementsByClassName("yk_openbtndiv")[0].style.marginTop = "100px";
}

function yk_closeNav() {
    document.getElementById("yk_mySidebar").style.height = "0";
    document.getElementsByClassName("yk_openbtndiv")[0].style.display = "block";
    setTimeout(function () {
        document.getElementsByClassName("yk_openbtndiv")[0].style.marginTop = "0";
    }, 100);
}
function yk_changeColor1() {
    document.getElementsByClassName("yk_closebtn")[0].style.color = "#f1f1f1";
    document.getElementsByClassName("yk_openbtn")[0].style.color = "#f1f1f1";
}
function yk_changeColor2() {
    document.getElementsByClassName("yk_closebtn")[0].style.color = "#818181";
    document.getElementsByClassName("yk_openbtn")[0].style.color = "#818181";
}

//////////////////////////
//请求后台执行方法
//获取弹幕
function getDanmu() {
    resultweb.TypeId = 1;
    resultweb.Type = "getDanmu";
    resultweb.Message = "";
    yk_consoleview();
    window.chrome.webview.postMessage(JSON.stringify(resultweb));
}
function yk_setLog() {
    resultweb.TypeId = 1;
    resultweb.Type = "SetLog";
    resultweb.Message = "";
    window.chrome.webview.postMessage(JSON.stringify(resultweb));
}


//////////////////////////
//控制台显示
function yk_consoleview() {
    var div = document.createElement('div');
    div.className = "A0ewbQCI Rr39Hb0T";
    div.style.cssText = "margin-left: 10px;";
    div.innerHTML = "<div class=\"n1iMhmEh\"><div class=\"BSMfxNI3 DTLdEOeJ\"><div class=\"FoccckN5\"></div><div class=\"X_dFr1vX\">控制台程序</div></div></div><div class=\"ro3xcipQ\"><div class=\"yk_consolecontent\" style=\"position: absolute; bottom: 0px;height:94%;width:100%;overflow-y: scroll;color: mediumpurple;font - size: 18px;padding: 0 15px; \"></div></div></div>";
    document.getElementsByClassName("SxCiQ8ip")[0].appendChild(div);
}
//控制台输出
var isscrollshow = true;//是否一直显示滚轮底部
function yk_consolelog(msg) {
    var div = document.createElement("div");
    console.log(msg);
    div.innerHTML = msg;
    document.getElementsByClassName("yk_consolecontent")[0].appendChild(div);
    
    if (yk_scrollbottom()) {
        if (document.getElementsByClassName("yk_consolecontent")[0].childNodes.length > 100) {
            document.getElementsByClassName("yk_consolecontent")[0].removeChild(document.getElementsByClassName("yk_consolecontent")[0].firstChild);
        }
        document.getElementsByClassName("yk_consolecontent")[0].scrollTo(0, document.getElementsByClassName("yk_consolecontent")[0].scrollHeight);
    }
    if (document.getElementsByClassName("yk_consolecontent")[0].childNodes.length > 200) {
        for (var i = 0; i < 100; i++) {
            document.getElementsByClassName("yk_consolecontent")[0].removeChild(document.getElementsByClassName("yk_consolecontent")[0].firstChild);
        }
        document.getElementsByClassName("yk_consolecontent")[0].scrollTo(0, document.getElementsByClassName("yk_consolecontent")[0].scrollHeight);
    }
}
//判断是否到达滚轮底部
function yk_scrollbottom() {
    return document.getElementsByClassName("yk_consolecontent")[0].scrollTop + document.getElementsByClassName("yk_consolecontent")[0].offsetHeight + 500 >= document.getElementsByClassName("yk_consolecontent")[0].scrollHeight;
}
//滚轮事件
function yk_scrollmove() {
    if (yk_scrollbottom()) {
        isscrollshow = true;
    } else {
        isscrollshow = false;
    }
}



document.getElementById("getDmId").onclick = getDanmu;
document.getElementById("yk_setlog").onclick = yk_setLog;
document.getElementsByClassName("yk_closebtn")[0].onclick = yk_closeNav;
document.getElementsByClassName("yk_closebtn")[0].onmouseenter = yk_changeColor1;
document.getElementsByClassName("yk_closebtn")[0].onmouseleave = yk_changeColor2;
document.getElementsByClassName("yk_openbtn")[0].onclick = yk_openNav;
document.getElementsByClassName("yk_openbtn")[0].onmouseenter = yk_changeColor1;
document.getElementsByClassName("yk_openbtn")[0].onmouseleave = yk_changeColor2;
//document.getElementsByClassName("yk_consolecontent")[0].onscroll = yk_scrollmove;
















